/*
@STI LICENSE
(C) 2006-2008 Universit�t Innsbruck.

This file is part of myOntology.

myOntologyis free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

myOntologyis distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with myOntology.  If not, see <http://www.gnu.org/licenses/>.

@STI LICENSE */
package view.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.DHTMLConstants;
import model.Vocabulary;

import org.apache.log4j.Logger;
import org.myontology.users.Login;
import org.openrdf.model.URI;
import org.openrdf.repository.RepositoryConnection;

import controller.HelperFunctions;
import controller.elementMapper.ClassMapper;
import controller.elementMapper.Mapper;
import controller.elementMapper.OntologyModuleMapper;
import controller.elementMapper.PropertyMapper;
import controller.sesameDataConnector.AbstractDataConnector;

/**
 * Servlet implementation class for Servlet: Update
 *
 */
public class Update extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

	 static final long serialVersionUID = 6L;
   
	 public static Logger logger = Logger.getLogger(Update.class);
	 
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public Update() {
		super();
	}   	

	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		
		
		if ( !Login.LOGGED_IN.getValue(request) ) {			
			response.sendRedirect( request.getContextPath() + "/login");
			return;
		}
		
		response.setContentType("text/xml;charset=utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setCharacterEncoding("UTF-8");
		
		String ret = "";

		String cssidcontent = request.getParameter( "cssidcontent" ).trim();
		String entry = request.getParameter( "entry" );
		String oldtimestamp = request.getParameter( "oldtimestamp" );
		String id = request.getParameter( "id" ).trim();

		entry = entry.replace("%23", "#" ); // for parameters containing "#"
		
		URI uri = null;
		
		String form = "";
		

		boolean shownavigation = true;
		boolean showcreatelinks = shownavigation;
		boolean shownavigationineditmode = shownavigation;
		
		try {

			RepositoryConnection con = AbstractDataConnector.getConnection();

			try {
				// uri = new URIImpl( id );
				uri =AbstractDataConnector.getURI( id );

				// the element which should be updated:			
				
				if( cssidcontent.equals( view.HTMLUIcomponents.Comment.CSSIDCONTENT ) ) {

					Mapper mapper = new Mapper();
					if( mapper.updateComment(
							con, 
							uri, 
							entry,
							oldtimestamp,
							Vocabulary.ENGLISH ) && mapper.exceptionsOccured()==false ) {

						con.commit();
						
						form = view.HTMLUIcomponents.Comment.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode, 
							Vocabulary.ENGLISH);
					}
					else {

						con.rollback(); 

						form = view.HTMLUIcomponents.Comment.getFormInEditMode(
							uri, 
							entry,
							mapper.getExceptionComment(), 
							shownavigation, 
							Vocabulary.ENGLISH );
					}
				}
				
				else if( cssidcontent.equals( view.HTMLUIcomponents.Tags.CSSIDCONTENT ) ) {

					Mapper mapper = new Mapper();
					if( mapper.updateTags( 
							con, 
							uri, 
							entry,
							oldtimestamp ) && mapper.exceptionsOccured()==false ) {

						con.commit();
						
						form = view.HTMLUIcomponents.Tags.getFormInViewMode( 
							uri, 
							shownavigation, 
							shownavigationineditmode );
					}
					else {

						con.rollback();

						form = view.HTMLUIcomponents.Tags.getFormInEditMode(
							uri, 
							entry,
							mapper.getExceptionsTags(), 
							shownavigation );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.Synonyms.CSSIDCONTENT ) ) {

					Mapper mapper = new Mapper();
					if( mapper.updateSynonyms( 
							con, 
							uri, 
							entry,
							oldtimestamp) && mapper.exceptionsOccured()==false ) {

						con.commit();
						
						form = view.HTMLUIcomponents.Synonyms.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );
					}
					else {

						con.rollback();

						form = view.HTMLUIcomponents.Synonyms.getFormInEditMode(
							uri, 
							entry, 
							mapper.getExceptionsSynonyms(), 
							shownavigation );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.SeeAlsos.CSSIDCONTENT ) ) {

					Mapper mapper = new Mapper();
					if( mapper.updateSeeAlso( 
							con, 
							uri, 
							entry,
							oldtimestamp ) && mapper.exceptionsOccured()==false ) {

						con.commit();
						
						form = view.HTMLUIcomponents.SeeAlsos.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );
					}
					else {

						con.rollback();

						form = view.HTMLUIcomponents.SeeAlsos.getFormInEditMode(
							uri, 
							entry,
							mapper.getExceptionsSeeAlsos(), 
							shownavigation );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.Example.CSSIDCONTENT ) ) {

					Mapper mapper = new Mapper();
					if( mapper.updateExample( 
							con, 
							uri, 
							entry,
							oldtimestamp ) && mapper.exceptionsOccured()==false ) {

						con.commit();
						
						form = view.HTMLUIcomponents.Example.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );
					}
					else {

						con.rollback();
						
						form = view.HTMLUIcomponents.Example.getFormInEditMode(
							uri, 
							entry,
							mapper.getExceptionsExamples(), 
							shownavigation );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.Translations.CSSIDCONTENT ) ) {

					Mapper mapper = new Mapper();
					if( mapper.updateTranslations( 
							con, 
							uri, 
							entry,
							oldtimestamp ) && mapper.exceptionsOccured()==false ) {

						con.commit();
						
						form = view.HTMLUIcomponents.Translations.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );
					}
					else {

						con.rollback();
						
						form = view.HTMLUIcomponents.Translations.getFormInEditMode(
							uri, 
							entry,
							mapper.getExceptionsTranslations(), 
							shownavigation );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.Images.CSSIDCONTENT ) ) {

					Mapper mapper = new Mapper();
					if( mapper.updateImages( 
							con, 
							uri, 
							entry,
							oldtimestamp ) && mapper.exceptionsOccured()==false ) {

						con.commit();
						
						form = view.HTMLUIcomponents.Images.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );

					}
					else {

						con.rollback();
						
						form = view.HTMLUIcomponents.Images.getFormInEditMode(
							uri, 
							entry,
							mapper.getExceptionsImages(), 
							shownavigation );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.Videos.CSSIDCONTENT ) ) {

					Mapper mapper = new Mapper();
					if( mapper.updateVideos( 
							con, 
							uri,
							entry, 
							oldtimestamp ) && mapper.exceptionsOccured()==false ) {

						con.commit();
						
						form = view.HTMLUIcomponents.Videos.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );

					}
					else {

						con.rollback();
						
						form = view.HTMLUIcomponents.Videos.getFormInEditMode(
							uri, 
							entry,
							mapper.getExceptionsVideos(), 
							shownavigation );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.ClassesBelongingToOM.CSSIDCONTENT ) ) {

					ArrayList<URI> entryList = HelperFunctions.extractURIs( entry ); 
					OntologyModuleMapper mapper = new OntologyModuleMapper();
					if( mapper.updateClassesBelongingToOM( 
							con, 
							uri, 
							entryList,
							oldtimestamp ) && mapper.exceptionsOccured()==false ) {

						con.commit();
						
						form = view.HTMLUIcomponents.ClassesBelongingToOM.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );
					}
					else {

						con.rollback();
						
						form = view.HTMLUIcomponents.ClassesBelongingToOM.getFormInEditMode(
							uri, 
							entryList,
							mapper.getExceptionClassesBelongingToOM(), 
							shownavigation,
							showcreatelinks );
					}					
				}
				else if (cssidcontent.equals("instanceeshavingclassindomaincontent")) {
					ArrayList<URI> entryList = HelperFunctions.extractURIs( entry ); 
					OntologyModuleMapper mapper = new OntologyModuleMapper();
					if( mapper.updateInstancesBelongingToOM( 
							con, 
							uri, 
							entryList,
							oldtimestamp ) && mapper.exceptionsOccured()==false ) {

						con.commit();
						
						form = view.HTMLUIcomponents.InstancesHavingDomainClass.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );
					}
					else {

						con.rollback();
						
						form = view.HTMLUIcomponents.InstancesHavingDomainClass.getFormInEditMode(
							uri, 
							entryList,
							mapper.getExceptionClassesBelongingToOM(), 
							shownavigation,
							showcreatelinks );
					}					
				}
				

				/*
				else if( cssidcontent.equals( view.HTMLUIcomponents.PropertiesBelongingToOM.CSSIDCONTENT ) ) {

					OntologyModuleMapper mapper = new OntologyModuleMapper();
					if( mapper.updatePropertiesBelongingToOM( 
							con, 
							uri, 
							entry,
							oldtimestamp ) && mapper.exceptionsOccured()==false ) {

						con.commit();
						
						form = view.HTMLUIcomponents.PropertiesBelongingToOM.getFormInViewMode(
							uri, 
							true );
					}
					else {

						con.rollback();
						
						form = view.HTMLUIcomponents.PropertiesBelongingToOM.getFormInEditMode(
							uri, 
							entry,
							mapper.getExceptionsPropertiesBelongingToOM(), 
							true );
					}					
				}
				*/

				else if( cssidcontent.equals( view.HTMLUIcomponents.PartlyOverlapsWith.CSSIDCONTENT ) ) {

					ArrayList<URI> entryList = HelperFunctions.extractURIs(entry);
					
					URI type = AbstractDataConnector.getType(uri);
					String viewType = null;
					if( type.equals(Vocabulary.CLASS) ) {
						viewType = DHTMLConstants.CLASS_VIEWTYPE;

						ClassMapper mapper = new ClassMapper();
						if( mapper.updatePartlyOverlapsWith( 
								con, 
								uri, 
								entryList,
								oldtimestamp ) && mapper.exceptionsOccured()==false ) {

							con.commit();
							
							form = view.HTMLUIcomponents.PartlyOverlapsWith.getFormInViewMode(
								uri,
								viewType,
								shownavigation, 
								shownavigationineditmode );
						}
						else {

							con.rollback();
							
							form = view.HTMLUIcomponents.PartlyOverlapsWith.getFormInEditMode(
								uri, 
								viewType,
								entryList,
								mapper.getExceptionPartlyOverlapsWith(), 
								shownavigation,
								showcreatelinks );
						}				
					}
					else if( type.equals(Vocabulary.DATATYPEPROPERTY) || type.equals(Vocabulary.OBJECTPROPERTY)) {

						viewType = DHTMLConstants.PROPERTY_VIEWTYPE;

						PropertyMapper mapper = new PropertyMapper();
						if( mapper.updatePartlyOverlapsWith( 
								con, 
								uri, 
								entryList,
								oldtimestamp ) && mapper.exceptionsOccured()==false ) {

							con.commit();
							
							form = view.HTMLUIcomponents.PartlyOverlapsWith.getFormInViewMode(
								uri,
								viewType,
								shownavigation, 
								shownavigationineditmode );
						}
						else {

							con.rollback();
							
							form = view.HTMLUIcomponents.PartlyOverlapsWith.getFormInEditMode(
								uri, 
								viewType,
								entryList,
								mapper.getExceptionPartlyOverlapsWith(), 
								shownavigation,
								showcreatelinks );
						}				
					}
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.SameAs.CSSIDCONTENT ) ) {

					ArrayList<URI> entryList = HelperFunctions.extractURIs(entry);
					
					URI type = AbstractDataConnector.getType(uri);
					String viewType = null;
					if( type.equals(Vocabulary.CLASS) ) {
						viewType = DHTMLConstants.CLASS_VIEWTYPE;

						ClassMapper mapper = new ClassMapper();
						if( mapper.updateSameAs( 
								con, 
								uri, 
								entryList,
								oldtimestamp ) && mapper.exceptionsOccured()==false ) {

							con.commit();
							
							form = view.HTMLUIcomponents.SameAs.getFormInViewMode(
								uri,
								viewType,
								shownavigation, 
								shownavigationineditmode );
						}
						else {

							con.rollback();
							
							form = view.HTMLUIcomponents.SameAs.getFormInEditMode(
								uri, 
								viewType,
								entryList,
								mapper.getExceptionSameAs(), 
								shownavigation,
								showcreatelinks );
						}				
					}
					else if( type.equals(Vocabulary.DATATYPEPROPERTY) || type.equals(Vocabulary.OBJECTPROPERTY)) {

						viewType = DHTMLConstants.PROPERTY_VIEWTYPE;

						PropertyMapper mapper = new PropertyMapper();
						if( mapper.updateSameAs( 
								con, 
								uri, 
								entryList,
								oldtimestamp ) && mapper.exceptionsOccured()==false ) {

							con.commit();
							
							form = view.HTMLUIcomponents.SameAs.getFormInViewMode(
								uri,
								viewType,
								shownavigation, 
								shownavigationineditmode );
						}
						else {

							con.rollback();
							
							form = view.HTMLUIcomponents.SameAs.getFormInEditMode(
								uri, 
								viewType,
								entryList,
								mapper.getExceptionSameAs(), 
								shownavigation,
								showcreatelinks );
						}				
					}
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.NarrowerThan.CSSIDCONTENT ) ) {

					ArrayList<URI> entryList = HelperFunctions.extractURIs(entry);
					
					URI type = AbstractDataConnector.getType(uri);
					String viewType = null;
					if( type.equals(Vocabulary.CLASS) ) {
						viewType = DHTMLConstants.CLASS_VIEWTYPE;
							
						ClassMapper mapper = new ClassMapper();
						if( mapper.updateNarrowerThan( 
								con, 
								uri, 
								entryList,
								oldtimestamp ) && mapper.exceptionsOccured()==false ) {
	
							con.commit();
							
							form = view.HTMLUIcomponents.NarrowerThan.getFormInViewMode(
								uri, 
								viewType,
								shownavigation, 
								shownavigationineditmode );
						}
						else {
	
							con.rollback();
							
							form = view.HTMLUIcomponents.NarrowerThan.getFormInEditMode(
								uri, 
								viewType,
								entryList,
								mapper.getExceptionNarrowerThan(), 
								shownavigation,
								showcreatelinks );
						}	
					}
					else if( type.equals(Vocabulary.DATATYPEPROPERTY) || type.equals(Vocabulary.OBJECTPROPERTY)) {

						viewType = DHTMLConstants.PROPERTY_VIEWTYPE;
							
						PropertyMapper mapper = new PropertyMapper();
						if( mapper.updateNarrowerThan( 
								con, 
								uri, 
								entryList,
								oldtimestamp ) && mapper.exceptionsOccured()==false ) {
	
							con.commit();
							
							form = view.HTMLUIcomponents.NarrowerThan.getFormInViewMode(
								uri, 
								viewType,
								shownavigation, 
								shownavigationineditmode );
						}
						else {
	
							con.rollback();
							
							form = view.HTMLUIcomponents.NarrowerThan.getFormInEditMode(
								uri, 
								viewType,
								entryList,
								mapper.getExceptionNarrowerThan(), 
								shownavigation,
								showcreatelinks );
						}	
					}
				}



				else if( cssidcontent.equals( view.HTMLUIcomponents.BroaderThan.CSSIDCONTENT ) ) {

					ArrayList<URI> entryList = HelperFunctions.extractURIs(entry);
					
					URI type = AbstractDataConnector.getType(uri);
					String viewType = null;
					if( type.equals(Vocabulary.CLASS) ) {
						viewType = DHTMLConstants.CLASS_VIEWTYPE;
							
						ClassMapper mapper = new ClassMapper();
						if( mapper.updateBroaderThan( 
								con, 
								uri, 
								entryList,
								oldtimestamp ) && mapper.exceptionsOccured()==false ) {
	
							con.commit();
							
							form = view.HTMLUIcomponents.BroaderThan.getFormInViewMode(
								uri, 
								viewType,
								shownavigation, 
								shownavigationineditmode );
						}
						else {
	
							con.rollback();
							
							form = view.HTMLUIcomponents.BroaderThan.getFormInEditMode(
								uri, 
								viewType,
								entryList,
								mapper.getExceptionNarrowerThan(), 
								shownavigation,
								showcreatelinks );
						}	
					}
					else if( type.equals(Vocabulary.DATATYPEPROPERTY) || type.equals(Vocabulary.OBJECTPROPERTY)) {

						viewType = DHTMLConstants.PROPERTY_VIEWTYPE;
							
						PropertyMapper mapper = new PropertyMapper();
						if( mapper.updateBroaderThan( 
								con, 
								uri, 
								entryList,
								oldtimestamp ) && mapper.exceptionsOccured()==false ) {
	
							con.commit();
							
							form = view.HTMLUIcomponents.BroaderThan.getFormInViewMode(
								uri, 
								viewType,
								shownavigation, 
								shownavigationineditmode );
						}
						else {
	
							con.rollback();
							
							form = view.HTMLUIcomponents.BroaderThan.getFormInEditMode(
								uri, 
								viewType,
								entryList,
								mapper.getExceptionNarrowerThan(), 
								shownavigation,
								showcreatelinks );
						}	
					}
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.SubClassOf.CSSIDCONTENT ) ) {

					ArrayList<URI> entryList = HelperFunctions.extractURIs(entry);
					ClassMapper mapper = new ClassMapper();
					if( mapper.updateSubclassOf( 
							con, 
							uri, 
							entryList,
							oldtimestamp ) && mapper.exceptionsOccured()==false ) {

						con.commit();
						
						form = view.HTMLUIcomponents.SubClassOf.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );
					}
					else {

						con.rollback();
						
						form = view.HTMLUIcomponents.SubClassOf.getFormInEditMode(
							uri, 
							entryList,
							mapper.getExceptionSubclassOf(), 
							shownavigation,
							showcreatelinks );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.Domain.CSSIDCONTENT ) ) {

					ArrayList<URI> entryList = HelperFunctions.extractURIs(entry);
					PropertyMapper mapper = new PropertyMapper();
					String oldentry = oldtimestamp; // workaround
					if( mapper.updateDomain( 
							con, 
							uri, 
							entryList,
							oldentry ) && mapper.exceptionsOccured()==false ) {
						
						con.commit();
						
						form = view.HTMLUIcomponents.Domain.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );	
					}
					else {

						con.rollback();
						
						form = view.HTMLUIcomponents.Domain.getFormInEditMode(
							uri, 
							entryList,
							mapper.getExceptionsDomain(), 
							shownavigation,
							showcreatelinks );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.Range.CSSIDCONTENT ) ) {

					ArrayList<URI> entryList = HelperFunctions.extractURIs(entry);
					PropertyMapper mapper = new PropertyMapper();
					if( mapper.updateRange( 
						con, 
						uri, 
						entryList,
						oldtimestamp ) && mapper.exceptionsOccured()==false ) {							

						con.commit();
						
						form = view.HTMLUIcomponents.Range.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );	
					}
					else {

						con.rollback();
						
						form = view.HTMLUIcomponents.Range.getFormInEditMode(
							uri, 
							entryList,
							mapper.getExceptionsRange(), 
							shownavigation,
							showcreatelinks );
					}
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.BelongsToOM.CSSIDCONTENT ) ) {

					ClassMapper mapper = new ClassMapper();
					String oldentry = oldtimestamp; // workaround
					ArrayList<URI> entryList = HelperFunctions.extractURIs(entry);
					if( mapper.updateBelongsToOM( 
							con,
							uri,
							entryList,
							oldentry ) && mapper.exceptionsOccured()==false ) {
						
						con.commit();
						
						form = view.HTMLUIcomponents.BelongsToOM.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );	
						
					} 
					else {

						con.rollback();
						
						form = view.HTMLUIcomponents.BelongsToOM.getFormInEditMode(
							uri, 
							entryList,
							mapper.getExceptionBelongsToOM(), 
							shownavigation,
							showcreatelinks );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.ClassesSubclassOfClass.CSSIDCONTENT ) ) {
						
					ArrayList<URI> entryList = HelperFunctions.extractURIs(entry);
					ClassMapper mapper = new ClassMapper(); 
					String oldentry = oldtimestamp; // workaround
					if( mapper.updateAllClassesHavingClassInSubClassOf(
							con, 
							uri,
							entry,
							oldentry ) && mapper.exceptionsOccured()==false ) {
						
						con.commit();
						
						form = view.HTMLUIcomponents.ClassesSubclassOfClass.getFormInViewMode(
							uri, 
							shownavigation,  
							shownavigationineditmode );	
						
					} else {

						con.rollback();
						
						form = view.HTMLUIcomponents.ClassesSubclassOfClass.getFormInEditMode(
							uri, 
							entryList,
							mapper.getExceptionAllClassesHavingClassInSubClassOf(), 
							shownavigation,
							showcreatelinks );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.PropertiesHavingDomainClass.CSSIDCONTENT ) ) {

					ArrayList<URI> entryList = HelperFunctions.extractURIs(entry);
					ClassMapper mapper = new ClassMapper(); 
					if( mapper.updateAllPropertiesHavingClassInDomain( 
							con, 
							uri,
							entryList,
							oldtimestamp ) && mapper.exceptionsOccured()==false ) {
						
						con.commit();
						
						form = view.HTMLUIcomponents.PropertiesHavingDomainClass.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );	
						
					} else {

						con.rollback();
						
						form = view.HTMLUIcomponents.PropertiesHavingDomainClass.getFormInEditMode(
							uri, 
							entryList,
							mapper.getExceptionAllPropertiesHavingClassInDomain(), 
							shownavigation,
							showcreatelinks );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.PropertiesHavingRangeClass.CSSIDCONTENT ) ) {

					ArrayList<URI> entryList = HelperFunctions.extractURIs(entry);
					ClassMapper mapper = new ClassMapper(); 
					String oldentry = oldtimestamp; // workaround
					if( mapper.updateAllPropertiesHavingClassInRange( 
							con, 
							uri,
							entry,
							oldentry ) && mapper.exceptionsOccured()==false ) {
						
						con.commit();
						
						form = view.HTMLUIcomponents.PropertiesHavingRangeClass.getFormInViewMode(
							uri, 
							shownavigation, 
							shownavigationineditmode );	
						
					} else {

						con.rollback();
						
						form = view.HTMLUIcomponents.PropertiesHavingRangeClass.getFormInEditMode(
							uri, 
							entryList,
							mapper.getExceptionAllPropertiesHavingClassInDomain(), 
							shownavigation,
							showcreatelinks );
					}					
				}

				else if( cssidcontent.equals( view.HTMLUIcomponents.Label.CSSIDCONTENT ) ) {
																
					Mapper mapper1 = new Mapper();
					// TODO: id k�nnte "" sein...
					URI type = AbstractDataConnector.getType( uri );

					URI newUri = mapper1.createElement(con, type, entry, uri );
					if( newUri!=null && mapper1.exceptionsOccured()==false ) {
												
						mapper1.insertLabel( con, newUri, entry, Vocabulary.ENGLISH );
						mapper1.insertComment(con, newUri, Mapper.selectComment(uri, Vocabulary.ENGLISH), Vocabulary.ENGLISH );
						mapper1.insertImages(con, newUri, Mapper.selectImages(uri) );
						mapper1.insertVideos(con, newUri, Mapper.selectVideos(uri) );
						mapper1.insertTranslations(con, newUri, Mapper.selectTranslation(uri) );
						mapper1.insertTags(con, newUri, Mapper.selectTags(uri) );
						mapper1.insertSynonyms(con, newUri, Mapper.selectSynonyms(uri) );
						
						mapper1.insertSeeAlso(con, newUri, Mapper.selectSeeAlso(uri) );
						
						if( type.equals(Vocabulary.CLASS)){
							ClassMapper mapper = new ClassMapper();

							mapper.insertExample(con, newUri, ClassMapper.selectExample(uri) );
							mapper.insertSubclassOf(con, newUri, ClassMapper.selectSubclassOf(uri) );
							mapper.insertAllPropertiesHavingClassInDomain( con, newUri, ClassMapper.selectAllPropertiesHavingClassInDomain(uri) );				

							mapper.updatePartlyOverlapsWith(con, newUri, ClassMapper.selectPartlyOverlapsWith(uri), null );
							mapper.updateSameAs(con, newUri, ClassMapper.selectSameAs(uri), null );
							mapper.insertNarrowerThan(con, newUri, ClassMapper.selectNarrowerThan(uri) );
							mapper.updateBroaderThan(con, newUri, ClassMapper.selectBroaderThan(uri), null );
							
							mapper.updateAllPropertiesHavingClassInRange( con, newUri, ClassMapper.selectAllPropertiesHavingClassInRange(uri), null );														
							mapper.updateAllClassesHavingClassInSubClassOf( con, newUri, ClassMapper.selectAllClassesHavingClassInSubClassOf(uri), null );
							mapper.updateBelongsToOM( con, newUri, ClassMapper.selectBelongsToOM(uri), null );
							
						}
						else if( type.equals(Vocabulary.ONTOLOGYMODULE)){
							OntologyModuleMapper mapper = new OntologyModuleMapper();

							mapper.insertClassesBelongingToOM( con, newUri, OntologyModuleMapper.selectClassesBelongingToOM( uri ) );
							// mapper.insertPropertiesBelongingToOM( con, newUri, OntologyModuleMapper.selectPropertiesBelongingToOM( uri ) );
							
						}
						else if( type.equals(Vocabulary.DATATYPEPROPERTY) || type.equals(Vocabulary.OBJECTPROPERTY)){
							PropertyMapper mapper = new PropertyMapper();
							
							mapper.insertExample( con, newUri, PropertyMapper.selectExample(uri) );							
							
							mapper.updateSameAs(con, newUri, PropertyMapper.selectSameAs(uri), null );
							mapper.updatePartlyOverlapsWith(con, newUri, PropertyMapper.selectPartlyOverlapsWith(uri), null );
							mapper.insertNarrowerThan(con, newUri, PropertyMapper.selectNarrowerThan(uri) );
							mapper.updateBroaderThan(con, newUri, PropertyMapper.selectBroaderThan(uri), null );
							
							mapper.insertRange(con, newUri, PropertyMapper.selectRange(uri));
							
							// mapper.updateBelongsToOM( con, newUri, PropertyMapper.selectBelongsToOM(uri), null );							
							mapper.updateDomain( con, newUri, PropertyMapper.selectDomain(uri), null );
						}
						
						con.commit();

						form = "";
					}
					else {
						
						con.rollback();
						
						form = view.HTMLUIcomponents.Label.getFormInEditMode(
							uri, 
							entry,
							type,
							mapper1.getExceptionLabel(), 
							shownavigation );	
					}
				}
			}
			catch( Exception e ) {
				con.rollback();
			}
			finally {
				con.close();
			}
		} catch( Exception e ) {
			logger.error( e );
		}

		ret = "<![CDATA[" + form + "]]>";
		
		// --------------------------

		ret = "<handleupdateresponse><" + cssidcontent + ">" + ret + "</" + cssidcontent + "></handleupdateresponse>";
		
	    PrintWriter out = response.getWriter();
		
	    out.println("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
	    
	    out.println( ret );
	}  	  	  	    
}
